Skip to content

Manual Combine Unloader — Call Unloader button for player-driven combines#1246

Open
antler22 wants to merge 5 commits intoCourseplay:mainfrom
antler22:feature/manual-unloader
Open

Manual Combine Unloader — Call Unloader button for player-driven combines#1246
antler22 wants to merge 5 commits intoCourseplay:mainfrom
antler22:feature/manual-unloader

Conversation

@antler22
Copy link
Copy Markdown

This feature adds a "Call Unloader" button to manually-driven combines (i.e. combines that the player is driving themselves, not Courseplay-controlled). When activated, a nearby Courseplay-managed grain cart automatically:

  1. Approaches the combine via pathfinding
  2. Positions itself under the combine's unloading pipe
  3. Follows the combine while it harvests (including through gentle curves and S-bends)
  4. Leaves when the player closes the pipe (2-second debounce prevents false exits)
  5. Automatically re-approaches if it loses position

The design goal is that the player only touches the button once — the grain cart handles everything until the pipe is closed.

Note: This PR replaces #1243, which was closed because it included unrelated personal preferences (US unit display). This branch contains only the manual unloader feature.


Files Changed

File Status Summary
scripts/ai/CpManualCombineProxy.lua New Proxy class mimicking AIDriveStrategyCombineCourse interface
scripts/specializations/CpAIFieldWorker.lua Modified cpToggleManualUnloader / cpIsManualCombineCallingUnloader toggle and proxy lifecycle
scripts/specializations/CpAIWorker.lua Modified Disable button/keybind for forage harvesters
scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua Modified Core unloader steering, off-track recovery, proximity fixes
scripts/ai/PurePursuitController.lua Modified Soft-recovery hook before hard CP shutdown
scripts/pathfinder/PathfinderUtil.lua Modified Defensive windrow filtering in hasFruit()
config/VehicleSettingsSetup.xml Modified Lower minimum for "Call Unloader At" setting to 20%
scripts/events/CpManualUnloaderEvent.lua New Multiplayer sync event for the toggle

Key Design Decisions

CpManualCombineProxy implements the full AIDriveStrategyCombineCourse interface so AIDriveStrategyUnloadCombine can interact with a manual combine using identical method calls — no nil checks or special-casing scattered through the unloader code.

isManualProxy() → true — marker method used to gate manual-only behavior in AIDriveStrategyUnloadCombine without re-querying the vehicle.

getFillLevelPercentage() → 1 — always reports full so fill level never causes the cart to leave. The only valid exit is isUnloadFinished() (pipe closed for 2+ seconds).

driveBesideCombine() direct goal point — for manual combines, a live goal point is computed every frame from the combine's AI direction node at the pipe's lateral offset, normalLookAheadDistance meters ahead. As the combine turns, the node rotates and the cart follows naturally through curves and gentle S-bends. The placeholder course (built from combine's current heading) exists only to satisfy PPC initialisation and is never consulted for steering.

PPC soft-recovery hookonOffTrackShutdown() in AIDriveStrategyUnloadCombine transitions the cart to IDLE instead of calling stopCurrentAIJob. The proxy's callUnloaderWhenNeeded() re-summons within ~2.5 s. The user never has to manually restart the grain cart.

Off-track grace periodoffTrackGracePeriodMs = 10000 (class default, unchanged). During active unloading, disableStopWhenOffTrack(5000) is called each tick, fully suppressing off-track detection while the cart is under the pipe.

Forage harvesters excluded — button and keybind are hidden when pipeSpec.numAutoAimingStates > 0. Their auto-aim spout geometry requires a separate implementation.


Backward Compatibility

All changes are backward-compatible with CP-driven combines:

  • Manual-only steering code is gated by combineStrategy:isManualProxy()
  • Shared fixes (proximity terrain ignore, PPC soft-recovery hook) benefit CP-driven unloaders as well
  • The callUnloaderPercent slider change (min 60% → 20%) applies to all combines

Known Limitations

  • Sharp turns (>~60°) cause the cart to lose tracking; soft recovery re-approaches within a few seconds
  • Forage harvesters are explicitly unsupported (button hidden)
  • Requires the grain cart to be running a Courseplay Combine Unloader job

antler22 and others added 3 commits April 25, 2026 11:38
Grain cart manual call button, US units, CP unload threshold dropped to 20%, pathfinding for grain cart
AIParameterSettingList.lua unit conversion stays in the personal fork/main
but is not part of the manual combine unloader feature for upstream.

Co-Authored-By: Claude Sonnet 4-6 <noreply@anthropic.com>
…f, remove unnecessary guards

- Rename cpIsCallGrainCartActive -> cpIsManualCombineCallingUnloader per pvaiko's naming suggestion
- Rename cpToggleCallGrainCart -> cpToggleManualUnloader for consistency
- Rename CallGrainCartEvent -> CpManualUnloaderEvent (class + file)
- Update translation key CP_callGrainCart -> CP_callManualUnloader; visible text now reads 'Call Unloader'
- Rebase PurePursuitController.lua on current upstream base so PR diff shows only our actual additions (~35 lines) instead of the full file
- Remove unnecessary if CollisionAvoidanceController / if ProximityController guards in AIDriveStrategyUnloadCombine.setAIVehicle() — these classes are always loaded
- Revert MotorController.lua to upstream (changes were unrelated to this feature and crept in by mistake)

Co-Authored-By: Claude Sonnet 4-6 <noreply@anthropic.com>
@antler22
Copy link
Copy Markdown
Author

@pvaiko — reopening as a clean feature-only PR replacing #1243. All of your review feedback has been addressed:

  • Naming updated throughout: cpIsManualCombineCallingUnloader, cpToggleManualUnloader, CpManualUnloaderEvent, and the HUD button now reads "Call Unloader"
  • PurePursuitController.lua rebuilt on the current upstream base — diff is now ~36 lines showing only the actual additions (grace-period constant, offTrackShutdownSince state, and the soft-recovery block)
  • CollisionAvoidanceController / ProximityController guards removed — both are now direct instantiation
  • MotorController.lua reverted to upstream — it was included by mistake in the previous commit
  • US unit changes (AIParameterSettingList.lua) are not in this branch — that stays in my personal fork only

Happy to discuss anything further or make adjustments.

Comment thread translations/translation_cz.xml Outdated
Comment thread translations/translation_ru.xml Outdated
Comment thread translations/translation_uk.xml Outdated
Comment thread scripts/pathfinder/PathfinderConstraints.lua Outdated
Comment thread scripts/pathfinder/PathfinderConstraints.lua Outdated
Comment thread scripts/pathfinder/PathfinderUtil.lua Outdated
Comment thread scripts/specializations/CpAIFieldWorker.lua
Comment thread scripts/specializations/CpAIWorker.lua
Comment thread scripts/specializations/CpCourseManager.lua
Comment thread scripts/ai/PurePursuitController.lua Outdated
Comment thread scripts/ai/PurePursuitController.lua Outdated
…C, use ImplementUtil.isChopper

- Revert PathfinderConstraints.lua to upstream (getFruitCheckDimensions removed; change was too restrictive and geometrically unsound)
- Revert translation_cz/ru/uk.xml to upstream (unintended edits)
- Restore nil guard for spec.courseDisplay in CpCourseManager.lua (accidentally dropped)
- Replace manual numAutoAimingStates chopper check with ImplementUtil.isChopper() in CpAIWorker.lua and CpFieldworkHudPage.lua
- Add explanatory comment to CpAIFieldWorker:onUpdate() for the CP-active auto-deactivation logic
- Simplify PPC off-track grace period: use g_time directly, remove onOffTrackShutdown() callback (pvaiko: AI slop)
- Remove ppc.offTrackGracePeriodMs override and onOffTrackShutdown() from AIDriveStrategyUnloadCombine.lua; rely on existing disableStopWhenOffTrack() calls

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua Outdated
Comment thread scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua
Comment thread scripts/ai/CpManualCombineProxy.lua Outdated
Comment thread scripts/ai/strategies/AIDriveStrategyCombineCourse.lua Outdated
Comment thread scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua Outdated
Comment thread scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua Outdated
Comment thread scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua Outdated
Comment thread scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua Outdated
Comment thread scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua Outdated
…, clean up guards

- CpManualCombineProxy: replace callUnloader() stub with isActiveCpCombine() returning true (correct approach per reviewer)
- AIDriveStrategyCombineCourse: revert to upstream — combine strategy not installed when manually driving
- PurePursuitController: revert to upstream — disableStopWhenOffTrack(5000) in the strategy is sufficient, grace period is redundant
- PathfinderUtil: revert to upstream — swath detection unconfirmed, defer to future iteration
- AIDriveStrategyUnloadCombine: remove do/end wrapper and self.ppc guard from disableStopWhenOffTrack call, fold into isManualProxy check; revert fill-level block to upstream; remove nil guards from harvesterStrategy calls in handleChopperTurn; remove redundant or-6 fallback on getWorkWidth(); handle manual blocker inline at blocking vehicle check

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

-- combine stopped in the meanwhile, like for example end of course
if combineStrategy:willWaitForUnloadToFinish() then
self:debug('change to unload stopped combine')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please revert this to keep logging consistent (also, state is logged already)

self:isInFrontAndAlignedToMovingCombine(true)
self:info('not in a good position to unload, cancelling rendezvous, trying to recover')
-- for some reason (like combine turned) we are not in a good position anymore then set us up again
self:info('unloadMovingCombine: EXIT - not in a good position (behind=%s, inFront=%s), startWaitingForSomethingToDo',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please revert this to keep logging consistent (also, state is logged already)

@pvaiko
Copy link
Copy Markdown
Contributor

pvaiko commented Apr 29, 2026

Thank you for addressing the comments so far, will continue the review as work permits...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants